package demo;
public class CurrentThread {
    //用任务类获取当前线程
    static class PrintTask implements Runnable{

        @Override
        public void run() {
            Thread thread=Thread.currentThread();
          //  System.out.println(thread==this); 无法比较，因为是任务，无法与线程比较
            System.out.println(thread.getName());
        }
    }
    //Thread子类获取当前线程
    static class PrintName extends Thread{

        @Override
        public void run() {
            //获取但当前线程
            Thread thread=Thread.currentThread();
            System.out.println(thread==this);
            //获取线程名
            System.out.println(thread.getName());
        }
    }


    public static void main(String[] args) {
        //

        PrintName t1=new PrintName();
        PrintName t2=new PrintName();
        PrintTask printTask=new PrintTask();
        Thread t3=new Thread(printTask);
        
        t1.start();
        t2.start();
        t3.start();

    }


}
